Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add operations to return WCS coordinates from argmin/argmax #680

Merged

Conversation

e-koch
Copy link
Contributor

@e-koch e-koch commented Oct 22, 2020

Revised version in #665 that does not depend on #656

Adds SpectralCube.argmin_world and SpectralCube.argmax_world to return the WCS coordinates of the argmin/max along a dimension. I've generalized a snippet from @low-sky for this.

The main use is creating "peak velocity" maps from a cube (i.e., velocity at peak intensity):

peak_velocity = cube.argmax_world(axis=0)
  • Add to docs pages
  • Finish docstrings

@coveralls
Copy link

coveralls commented Oct 22, 2020

Coverage Status

Coverage increased (+0.03%) to 86.267% when pulling 1448c8e on e-koch:add_wcs_argmin_max_operations into 71fd8e2 on radio-astro-tools:master.

@e-koch e-koch changed the title Add operations to return WCS coordinates from argmin/argmax - Take 2 Add operations to return WCS coordinates from argmin/argmax Oct 24, 2020
@keflavich
Copy link
Contributor

Where do we stand on this? You need review? Rebase?

@e-koch
Copy link
Contributor Author

e-koch commented Nov 10, 2020

Rebase. Will do by the end of the day

@codecov-io
Copy link

codecov-io commented Nov 11, 2020

Codecov Report

Merging #680 (3b7a75d) into master (84c48c8) will increase coverage by 0.14%.
The diff coverage is 97.91%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #680      +/-   ##
==========================================
+ Coverage   80.19%   80.34%   +0.14%     
==========================================
  Files          24       24              
  Lines        5505     5552      +47     
==========================================
+ Hits         4415     4461      +46     
- Misses       1090     1091       +1     
Impacted Files Coverage Δ
spectral_cube/cube_utils.py 80.16% <94.11%> (+0.98%) ⬆️
spectral_cube/spectral_cube.py 84.10% <100.00%> (+0.26%) ⬆️
spectral_cube/wcs_utils.py 91.83% <100.00%> (+0.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 84c48c8...3b7a75d. Read the comment docs.

@e-koch
Copy link
Contributor Author

e-koch commented Nov 11, 2020

@astrofrog @keflavich This is ready!

Copy link
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this but I wonder if we should return all world coordinates - there are cases where the RA/Dec may not line up with the pixel axes, for example they may be rotated by 45 deg. So then if you called argmax_world(axis=1) it's not clear if what would be returned is RA or Dec. Picking the world coordinate with the same index as the pixel axis only make sense in the cases where pixel and world axes are aligned?

spectral_cube/cube_utils.py Show resolved Hide resolved
spectral_cube/cube_utils.py Outdated Show resolved Hide resolved
spectral_cube/cube_utils.py Outdated Show resolved Hide resolved
@keflavich
Copy link
Contributor

@astrofrog Is this presently going to return incorrect results in the case of a rotated WCS? If so, we should special-case this for aligned axes only (we have that ability in generalized WCS, right?), and punt the general case for now. I'm not sure how much use there is for the general case anyway.

@e-koch
Copy link
Contributor Author

e-koch commented Nov 12, 2020

@astrofrog @keflavich Here's the check I added for correlated image -> WCS axes: https://github.com/radio-astro-tools/spectral-cube/pull/680/files#diff-5efbc7ba09eb93125b163d09f8107e93a24aac38ed8791ef0b17b5ffb2fbea18R486

My understanding of axis_correlation_matrix is that the celestial axes will always be labeled as correlated, so argmin_world/argmax_world will only work for the spectral axis without.

I'm wondering if the changes in this PR should be restricted to only the spectral axis. I'm now not sure that any other case is well defined

@e-koch
Copy link
Contributor Author

e-koch commented Nov 19, 2020

Current failures will be fixed in #688

@e-koch e-koch force-pushed the add_wcs_argmin_max_operations branch from b06c187 to eb56512 Compare November 27, 2020 15:15
@e-koch
Copy link
Contributor Author

e-koch commented Nov 27, 2020

@astrofrog Can you have a quick look through the new changes? I've added checks for correlated pixel -> WCS axes.

This otherwise ready to go, IMO

Copy link
Contributor

@keflavich keflavich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, though I have suggestions on the docstring.

also, there's a lot of duplicated code between argmax/argmin. Could we combine those into one with method='max'/method='min' and just pick between them, then have argmin_world just return argminmax_world(method='max', **kwargs) ?

docs/moments.rst Outdated Show resolved Hide resolved
spectral_cube/cube_utils.py Outdated Show resolved Hide resolved
@e-koch
Copy link
Contributor Author

e-koch commented Dec 3, 2020

@keflavich -- Thanks for the suggestion. I've added _argminmax_world with the common code.

I think this is ready to merge if these last tests pass.

@keflavich keflavich merged commit af23e86 into radio-astro-tools:master Dec 4, 2020
@e-koch e-koch deleted the add_wcs_argmin_max_operations branch December 4, 2020 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants